package com.dm.logistics.conservemanage.controller;

import com.dm.logistics.conservemanage.service.ConseService;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Transactional
@Controller
@CrossOrigin
public class ConseController {

    private static final Logger logger = LoggerFactory.getLogger(ConseController.class);
    @Autowired
    private ConseService conseService;

    /**
         * @Description 查询所有维修单信息
         * @Author zhangxue
         * @Date 9:00 2018/5/8
         * @Param
         * @retrun
         **/
    @RequestMapping(value = "/queryAllConseDoc",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllConseDoc(@RequestBody Map<String,Object> map) {
        Map<String,Object> resultMap = conseService.queryAllConseDoc(map);
        String result = resultMap.get("serviceList")!=null?resultMap.get("serviceList").toString():null;
        return result;
    }

    /**
     * @Description  提交维修单
     * @Author zhangxue
     * @Date 17:09 2018/5/7
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/saveConseDoc",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String saveConseDoc(@RequestBody Map<String,Object> map) {
        Map<String,Object> resultMap = conseService.saveConseDoc(map);
        JSONObject jsonObject = JSONObject.fromObject(resultMap);
        return jsonObject.toString();
    }

    /**
         * @Description 执行待执行维修单
         * @Author zhangxue
         * @Date 15:24 2018/5/8
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/saveConseDocAndConseCourse",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String saveConseDocAndConseCourse(@RequestBody Map<String,Object> map) {
        Map<String,Object> resultMap = conseService.saveConseDocAndConseCourse(map);
        JSONObject jsonObject = JSONObject.fromObject(resultMap);
        return jsonObject.toString();
    }

    /**
         * @Description 查询执行完成的维修单
         * @Author zhangxue
         * @Date 16:58 2018/5/8
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryBasicEquAndConseInfos",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryBasicEquAndConseInfos(@RequestBody Map<String,Object> map) {
        Map<String,Object> resultMap = conseService.queryBasicEquAndConseInfos(map);
        JSONObject jsonObject = JSONObject.fromObject(resultMap);
        return jsonObject.toString();
    }

    /**
         * @Description  刪除維修單
         * @Author zhangxue
         * @Date 11:19 2018/5/14
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/deleteConseveById",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String deleteConseveById(@RequestBody Map<String,Object> map) {
        Map<String,Object> resultMap = conseService.deleteConseveById(map);
        JSONObject jsonObject = JSONObject.fromObject(resultMap);
        return jsonObject.toString();
    }

    /**
     * @Description 导出Excel
     * @Author zhangxue
     * @Date 14:55 2018/6/14
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/CreateConseExcel",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> CreateConseExcel(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = conseService.CreateAssessExcel2(param);
        return statusMap;
    }
}
